package org.example.controller;

import org.example.commons.ApiResponse;
import org.example.goods.api.ItemFeignClient;
import org.example.goods.api.ItemRequest;
import org.example.goods.api.ItemResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RefreshScope
public class IndexController {

    @Value("${config}")
    private String config;

    @Resource
    private ItemFeignClient itemFeignClient;

    @GetMapping("/index")
    public ApiResponse<String> index() {
        ApiResponse<ItemResponse> item = itemFeignClient.getItem(new ItemRequest(1L));
        return ApiResponse.success("ok" + config + item.getData().getName());
    }
}
